 package scripting.item;

 import client.MapleClient;
 import client.inventory.Item;
 import client.skills.Skill;

 import client.skills.SkillFactory;
 import constants.ItemConstants;
 import constants.JobConstants;
 import constants.ScriptType;
 import javax.script.Invocable;
 import scripting.npc.NPCConversationManager;
 import server.MapleInventoryManipulator;
 import tools.MaplePacketCreator;













 public class ItemActionManager
   extends NPCConversationManager
 {
   private final Item item;

   public ItemActionManager(MapleClient c, int npc, Item item, Invocable iv) {
/*  34 */     super(c, npc, String.valueOf(item.getItemId()), ScriptType.ITEM, iv);
/*  35 */     this.item = item;
   }


   public void dispose() {
/*  40 */     dispose(-1);
   }






   public void dispose(int remove) {
/*  49 */     if (remove == 0) {
/*  50 */       usedAll();
/*  51 */     } else if (remove > 0) {
/*  52 */       used(remove);
     }
/*  54 */     ItemScriptManager.getInstance().dispose(getClient());
   }






   public Item getItem() {
/*  63 */     return this.item;
   }






   public int getItemId() {
/*  72 */     return this.item.getItemId();
   }






   public short getPosition() {
/*  81 */     return this.item.getPosition();
   }






   public boolean used() {
/*  90 */     return used(1);
   }







   public boolean used(int q) {
/* 100 */     return MapleInventoryManipulator.removeFromSlot(getClient(), ItemConstants.getInventoryType(getItemId()), getPosition(), (short)q, true, false);
   }




   public void remove() {
/* 107 */     remove(1);
   }






   public void remove(int quantity) {
/* 116 */     used(quantity);
   }






   public boolean usedAll() {
/* 125 */     return MapleInventoryManipulator.removeFromSlot(getClient(), ItemConstants.getInventoryType(getItemId()), getPosition(), this.item.getQuantity(), true, false);
   }







   public String getSkillMenu(int skillMaster) {
/* 135 */     StringBuilder sb = new StringBuilder();

/* 137 */     getPlayer().getSkills().forEach((key, value) -> {
           Skill skill = SkillFactory.getSkill(key.intValue());
           if (JobConstants.getSkillBookByJob(key.intValue() / 10000) > 2 && skill.getMaxLevel() > 10 && value.masterlevel < skill.getMaxLevel()) {
             if (skillMaster > 20) {
               if (value.masterlevel < 30 && value.masterlevel >= 20 && skill.getMaxLevel() > 20) {
                 sb.append("\r\n#L").append(key).append("# #s").append(key).append("# #fn黑体##fs14##e#q").append(key).append("##n#fs##fn##l");
               }
             } else if (value.masterlevel < 20) {
               sb.append("\r\n#L").append(key).append("# #s").append(key).append("# #fn黑体##fs14##e#q").append(key).append("##n#fs##fn##l");
             }
           }
         });
/* 149 */     return sb.toString();
   }

   public boolean canUseSkillBook(int skillId, int masterLevel) {
/* 153 */     if (masterLevel > 0) {
/* 154 */       Skill skill = SkillFactory.getSkill(skillId);
/* 155 */       if (getPlayer().getSkillLevel(skill) >= skill.getMaxLevel()) {
/* 156 */         return false;
       }
/* 158 */       int skillLevel = getPlayer().getSkillLevel(skill);
/* 159 */       if ((skillLevel >= 5 && masterLevel == 20) || (skillLevel >= 15 && masterLevel == 30)) {
/* 160 */         return true;
       }
     }
/* 163 */     return false;
   }

   public void useSkillBook(int skillId, int masterLevel) {
/* 167 */     Skill skill = SkillFactory.getSkill(skillId);
/* 168 */     masterLevel = (masterLevel > skill.getMaxLevel()) ? skill.getMaxLevel() : masterLevel;
/* 169 */     getPlayer().changeSingleSkillLevel(skill, getPlayer().getSkillLevel(skill), (byte)masterLevel);
/* 170 */     getPlayer().getMap().broadcastMessage(MaplePacketCreator.useSkillBook(getPlayer(), 0, 0, true, true));
/* 171 */     enableActions();
   }

   public void useFailed() {
/* 175 */     getMap().broadcastMessage(MaplePacketCreator.useSkillBook(getPlayer(), 0, 0, true, false));
/* 176 */     enableActions();
   }
 }


/* Location:              C:\PGX\Server.jar!\scripting\item\ItemActionManager.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */